package com.restaurant.springboot.controller;

import com.restaurant.springboot.entity.DishesSeriesEntity;
import com.restaurant.springboot.service.DishesSeriesService;
import com.restaurant.springboot.service.DishesService;
import com.restaurant.springboot.utils.RespCode;
import com.restaurant.springboot.utils.RespEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/dishesSeries")
public class DishesSeriesController {

    @Autowired
    private DishesSeriesService dishesSeriesService;

    @Autowired
    private DishesService dishesService;


    /**
     * 获取所有菜品类别
     * @return
     */
    @GetMapping("")
    public RespEntity getAllDishesSeries(){
        return new RespEntity(RespCode.SUCCESS,dishesSeriesService.getAllDishesService());
    }

    /**
     * 通过菜品类id获取菜品类信息
     * @param dishesSeriesId
     * @return
     */
    @GetMapping("{dishesSeriesId}")
    public RespEntity getDishesSeriesById(@PathVariable int dishesSeriesId){
        return new RespEntity(RespCode.SUCCESS,dishesSeriesService.getDishesByDishesSeriesId(dishesSeriesId));
    }

    /**
     * 获取一个菜品类的所有菜品信息
     * @param dishesSeriesId
     * @return
     */
    @GetMapping("dishes/{dishesSeriesId}")
    public RespEntity getAllDishesBySeriesId(@PathVariable  int dishesSeriesId){
        return new RespEntity(RespCode.SUCCESS,dishesService.getDishesBySeriesId(dishesSeriesId));
    }

    /**
     * 获取所有菜品类菜品，按菜品类分
     * @return
     */
    @GetMapping("/dishes")
    public RespEntity getAllDishesOrderBySeries(){
        List<DishesSeriesEntity> dishesSeries = dishesSeriesService.getAllDishesService();
        Map<String,Object> result = new HashMap<>();
        for(DishesSeriesEntity dishesSeriesEntity:dishesSeries){
            result.put(dishesSeriesEntity.getName(),dishesService.getDishesBySeriesId(dishesSeriesEntity.getId()));
        }
        return new RespEntity(RespCode.SUCCESS,result);
    }



}
